<!DOCTYPE html>
<html lang="en"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>accessTestConfig</title>
    <link rel="stylesheet" type="text/css" th:href="@{/css/themes/default/easyui.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/css/themes/icon.css}">
    <script type="text/javascript" th:src="@{/js/jquery.min.js}"></script>
    <script type="text/javascript" th:src="@{/js/jquery.easyui.min.js}"></script>
    <style type="text/css" title="currentStyle" media="screen" mce_bogus="1">
        .divcenter{
            position:absolute;/*层漂浮*/
            top:35%;
            left:35%;
            width:30%;
            height:30%;
            /* background:yellow;   */
             border:1px solid red;
        }
    </style>
</head>
<body>
<!-- 顶部菜单导航，用户信息栏-->
<div th:replace="baseHeader::baseheader"></div>
<div class="center" style="width:100%;">
    <div class="opt">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" onclick="fnAddMonitorCode()">新增</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="fnUpdateMonitorCode(1)">启动</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-no" onclick="fnUpdateMonitorCode(0)">暂停</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-clear" onclick="removeMonitorCode()">删除</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit"  onclick="editMonitorCode()">编辑</a>
    </div>
    <table id="dg_monitorCode" class="easyui-datagrid" title="检测程序列表" style="width:100%;height:600px"
           data-options="singleSelect:true,collapsible:true,url:'getMonitorCodeList',method:'get',pagination:true,pageSize:10,pageNumber:1">
        <thead>
        <tr>
            <th data-options="field:'monitorcodeId',width:'10%' ,align:'center'">检测程序Id</th>
            <th data-options="field:'monitorcodeDesc',width:'13%' ,align:'center'">检测程序描述</th>
            <th data-options="field:'monitorobjType',width:'6%' ,align:'center'">监视对象类型</th>
            <th data-options="field:'ipAddress',width:'6%' ,align:'center'">IP</th>
            <th data-options="field:'netport',width:'4%' ,align:'center'">port端口</th>
            <th data-options="field:'url',width:'11%' ,align:'center'">url</th>
            <th data-options="field:'databaseType',width:'4%' ,align:'center'">数据库类型</th>
            <th data-options="field:'otherinfo',width:'12%' ,align:'center'">其他信息</th>
            <th data-options="field:'remark',width:'8%' ,align:'center'">备注</th>
            <th data-options="field:'effective',width:'4%' ,align:'center'">有效性</th>
            <th data-options="field:'updatetime',width:'10%' ,align:'center'">更新时间</th>
            <th data-options="field:'lastexecutetime',width:'10%' ,align:'center'">上次执行时间</th>
            <!--<th data-options="field:'opr',width:'15%' ,align:'center',formatter:formatOpr">操作</th>-->
        </tr>
        </thead>
    </table>
</div>
<!-- 编辑检测程序信息-->
<div class="easyui-dialog" id="editMonitorCodeWin" title="editMonitorObj" style="width:500px;height:400px;padding:10px">
    <div  th:replace="editMonitorCode::editMonitorCode" style="height: 100%;width: 100%"></div>
</div>
</body>
</html>
<script>
    $(document).ready(function() {
        $('#editMonitorCodeWin').dialog('close')
    })

    function fnAddMonitorCode(){
        console.log("新增")
        $('#editMonitorCodeWin').dialog('open');
        $('#ff').form('load',{
            monitorcodeId:""
        });
    }

    function fnUpdateMonitorCode(effective){
        console.log("启用/禁用")
        var row = $('#dg_monitorCode').datagrid('getSelected');
        if(row){
            $.ajax({
                url:'updateMonitorCodeInfo',
                method:"post",
                data:{
                    monitorcodeId:row.monitorcodeId,
                    effective:effective
                },
                success:function(data){
                    if(effective){
                        alert('启用成功！');
                    }else{
                        alert('暂停成功！');
                    }

                    reloadGrid()
                }
            });
        }else {
            alert('请先选择一行');
        }
    }

    function removeMonitorCode(){
        console.log("删除")
        var row = $('#dg_monitorCode').datagrid('getSelected');
        if(row){
            $.messager.confirm('删除操作确认', '确定执行删除操作吗?', function(r){
                if (r){
                    $.ajax({
                        url:'removeMonitorCode',
                        method:"post",
                        data:{
                            monitorcodeId:row.monitorcodeId,
                        },
                        success:function(data){
                            alert('删除成功！');
                            reloadGrid()
                        }
                    });
                }
            })
        }else {
            alert('请先选择一行');
        }
    }

    function editMonitorCode(){
        console.log("编辑")
        var row = $('#dg_monitorCode').datagrid('getSelected');
        if (row){
            $('#editMonitorCodeWin').dialog('open');
            $('#ff').form('load',{
                monitorcodeId:row.monitorcodeId,
                monitorcodeDesc:row.monitorcodeDesc,
                monitorobjType:row.monitorobjType,
                ipAddress:row.ipAddress,
                netport:row.netport,
                url:row.url,
                databaseType:row.databaseType,
                otherinfo:row.otherinfo,
                remark:row.remark
            });
        }else{
            alert('请先选择一行');
        }
    }

    function reloadGrid() {
        $('#dg_monitorCode').datagrid('reload');
    }



</script>
